// pages/home/components/supplement/supplement.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    yearArray: '1996',
    buildArray: ['板楼', '塔楼', '板塔结合', '平房'],
    renovationArray: ['豪华装', '精装', '简装', '毛坯'],
    areaArray: ['有', '无', '不清楚'],
    buildId: -1,
    renovaId: -1,
    areaId: -1,
    buildInfo: '',
    renovationInfo: '',
    areaInfo: '',
    supplementInfo: {}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.setNavigationBarTitle({
      title: '补充信息'
    })
  },
  bindDateChange: function (e) { // 年的选择
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      yearArray: e.detail.value
    })
  },
  buildBut (e) { // 建筑类型选择
    const ind = e.currentTarget.dataset.id;
    const buildInfo = this.data.buildArray[ind];
    this.setData({
      buildId: ind,
      buildInfo: buildInfo
    })
  },
  renovationBut (e) { // 装修类型选择
    const ind = e.currentTarget.dataset.id;
    const renovationInfo = this.data.renovationArray[ind]
    this.setData({
      renovaId: ind,
      renovationInfo: renovationInfo
    })

  },
  areaBut(e) { // 额外面积选择
    const ind = e.currentTarget.dataset.id;
    const areaInfo = this.data.areaArray[ind]
    this.setData({
      areaId: ind,
      areaInfo: areaInfo
    })
  },
  supplementBut () { // 点击提交
    this.data.supplementInfo.build = this.data.buildId
    this.data.supplementInfo.renovation = this.data.renovaId
    this.data.supplementInfo.area = this.data.areaId
    wx.setStorageSync('supplementInfo', this.data.supplementInfo) // 存储到本地
    const InfoTotal = {
      year: this.data.yearArray,
      build: this.data.buildInfo,
      renovation: this.data.renovationInfo,
      area: this.data.areaInfo
    }
    console.log(InfoTotal)
    wx.navigateBack({
      delta: 1
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    console.log(2222)
    var that = this;
    wx.getStorage({
      key: 'supplementInfo',
      success: function(res) {
        console.log(res)
        const data = res.data
        that.setData({
          buildId: data.build,
          renovaId: data.renovation,
          areaId: data.area,
        })
      },
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
  }
})